import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path/path.dart';
import 'package:ugrownews_flutter/load/ScreenLoad.dart';
import 'package:ugrownews_flutter/main/ScreenNewsDetail.dart';
import 'package:ugrownews_flutter/utils/DatabaseUtil.dart';
import 'package:ugrownews_flutter/utils/RouterUtil.dart';
import 'package:ugrownews_flutter/utils/UGrowColors.dart';
import 'package:ugrownews_flutter/utils/jpush_flutter.dart';
import 'package:fluro/fluro.dart';

BuildContext _buildContext;

void main() {
  //保持竖屏
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
  runApp(MyApp());
  //以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = new SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.light,
        statusBarBrightness: Brightness.light);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
  //初始化耗时任务，保证启动页的时候完成，保证主之后使用
  //初始化颜色
  _initColor();
  //初始化数据库，用于缓存http请求
  _initDatabase();
  _initFlour();
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    _buildContext = context;
    return MaterialApp(
      //显示帧率
//      showPerformanceOverlay: true,
      title: 'UGrowNews',
      home: new Scaffold(
        body: new LoadScreen(),
      ),
    );
  }
}

void _initColor() async {
  UGrowColors.initColor();
}

void _initDatabase() async {
  DatabaseUtil.initDatabase();
}

void _initFlour() async {
  RouterUtil.initRouter();
}
